#include "organize.h"

Student s;

void printTitle()
{
    system("cls");
    cout << "==========Student Client==========\n";
    cout << "-------------Options-------------\n";
    cout << "1.change password  2.view scores\n";
    cout << "3.exit\n---------------------------------\n";
    cout << "What do you want to do? Input the serial number:";
}

bool login(Student &s)
{
    system("cls");
    cout << "==========Student Client==========\n";
    cout << "Login with your id:";
    string id, pswd;
    cin >> id;
    s = findStudentById(id, "./data/studentInfo.txt");
    while (s.id == "#")
    {
        cout << "No such id. Please try again!\nLogin with your id:";
        cin >> id;
        s = findStudentById(id, "./data/studentInfo.txt");
    }
    cout << id << "'s password:";
    cin >> pswd;
    if (pswd == s.password)
        return true;
    else
        return false;
}

void viewScore()
{
    return;
}

int main()
{
    while (!login(s))
    {
        cout << "Your id or password is wrong. Please try again!\n";
        system("pause");
    }
    cout << "Welcome! " << s.name << '!' << endl;
    system("pause");
    int cmd;
    printTitle();
    while (cin >> cmd)
    {
        switch (cmd)
        {
        case 1:
            s.pswdChange();
            break;
        case 2:
            viewScore();
            break;
        case 3:
            cout << "Byebye!" << s.name << '!' << endl;
            system("pause");
            return 0;
        default:
            cout<<"No such option!\n";
            system("pause");
            break;
        }
        printTitle();
    }
    system("pause");
    return 0;
}